"""
实现fps的计算
创建者：Carburn Ashroom
2024.1.18
"""

from time import time

import config


class FpsCalc:
    """FpsCalc类是一个Fps计算器"""
    def __init__(self, ref=config.FPS_REFRESH):
        self.itv = ref
        self.frames = 0
        self.fps = 0
        self.start = time()

    def add(self):
        """计入一帧"""
        self.frames += 1
        if self.frames == self.itv:
            end = time()
            self.fps = self.frames / (end-self.start)
            self.start = end
            self.frames = 0
